package com.yuhs.zixing.study.design.pattern.dp001.principle.p03.dependency.inversion;

/**
 * @description 分析 DependencyInversionDemo001
 * 如果person获取消息的对象是微信、短信等类型的信息呢？
 * 需要新增类，同时信息person类的接收方法。
 * 思路：引入一个抽象的接口类 ReceiverInterface 表示接受者，这样person与ReceiverInterface发生依赖关系
 * 微信、email、短信等都是属于接收范围，各自实现ReceiverInterface接口
 * 这样我们就符合依赖倒置的原则了
 * @author: yuhs
 * @date 2022/3/25 下午7:40
 */
public class DependencyInversionDemo002 {
    public static void main(String[] args) {
        Person002 person = new Person002();
        person.receive(new Email002());
        person.receive(new WeiXin002());
    }
}

interface ReceiverInterface {
    String getInfo();
}

class Email002 implements ReceiverInterface {
    @Override
    public String getInfo() {
        return "002电子邮件信息：hello,world";
    }
}

class WeiXin002 implements ReceiverInterface {
    @Override
    public String getInfo() {
        return "002 WeiXin002消息：hello,world";
    }
}

/**
 * 完成Person接收消息
 */
class Person002 {
    public void receive(ReceiverInterface email) {
        System.out.println("接收信息：" + email.getInfo());
    }

}
